home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 691 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  51 lines

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. Newsgroups: comp.std.c
  3. Subject: Re: Initializing a variable in terms of itself
  4. Message-ID: <danpop.828455346@rscernix>
  5. From: danpop@mail.cern.ch (Dan Pop)
  6. Date: 2 Apr 96 14:29:06 GMT
  7. References: <4jpj9l$ik9@cnn.Princeton.EDU>
  8. Organization: CERN European Lab for Particle Physics
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4jpj9l$ik9@cnn.Princeton.EDU> tim@franck (Tim Hollebeek) writes:
  13.  
  14. >Just out of curiosity, is this legal?
  15. >
  16. >int main() {
  17. >    int x = x;
  18. >    return 0;
  19. >}
  20.  
  21. ANSI classic 1.6:
  22.  
  23.  * Undefined behavior --- behavior, upon use of a nonportable or
  24.    erroneous program construct, of erroneous data, or of
  25.    indeterminately-valued objects, for which the Standard imposes no
  26.    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  27.    requirements.  Permissible undefined behavior ranges from ignoring the
  28.    situation completely with unpredictable results, to behaving during
  29.    translation or program execution in a documented manner characteristic
  30.    of the environment (with or without the issuance of a diagnostic
  31.    message), to terminating a translation or execution (with the issuance
  32.    of a diagnostic message).
  33.  
  34. ANSI classic 3.5.7:
  35.  
  36.     If an object that has automatic storage duration is not initialized
  37.     explicitly, its value is indeterminate.
  38.  
  39. So it's illegal, but a diagnostic isn't required.
  40.  
  41. >gcc compiles it without even a warning, suprisingly. 
  42.  
  43. Why "suprisingly"?  It doesn't complain about i=i++ either.
  44.  
  45. Dan
  46. --
  47. Dan Pop
  48. CERN, CN Division
  49. Email: danpop@mail.cern.ch 
  50. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  51.